Skip to content

A link follows a definition renamed as it moves to another file or scope - #1672

Merged
zlareb1 merged 8 commits into
mainfrom
feat/links-follow-rename-across-files
Nov 28, 2026
Merged

zlareb1 merged 8 commits into
mainfrom
feat/links-follow-rename-across-files

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Related: #1669

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A memory's code link follows a definition that is renamed as it moves to another file, class or namespace: moved when only its name changed, changed when it was edited or left its class. Such a link read missing before, and under the default retire_removed policy its memory left search although the code lives on.

Why

When a linked definition's name is gone from its file, the recheck looked for a renamed successor only in that file and scope (_renamed, successor.successor), and in other files only for the same qualified or module-local name (_elsewhere, _in_mirror, anchor.locate). A definition renamed in the commit that moved it was never a candidate, so the link read missing.

Measured on 882 labelled events (renames, moves, edits, merges, deletions) mined from the history of eight open-source Python repositories, one link followed over one commit by the real _recheck against bare clones, with no ClickHouse:

  • move and rename, body at least 0.95 alike: 0 of 90 followed, 79 missing;
  • move, rename and edit: 0 of 55, 41 missing;
  • own name kept, scope changed, in the same file: 5 of 40 followed with a near-identical body, 1 of 25 with an edit;
  • 230 of the 722 events whose code lives on read missing (32%).

The recheck now also weighs the definitions the changed files did not define at the range's base, in any file or scope, where every earlier search found nothing:

  1. The only one with the old definition's exact shape is followed as a rename alone: moved, or changed when a member did not arrive with its class unchanged. A definition under 30 tokens is a candidate only under a name of the same words and with its scope (the first two guards below).
  2. Failing that, the only one of its own bare name with a close text is followed as changed.
  3. Two candidates, or one that another removed definition may have become, leave the link unresolved. Such a link is looked for from the commit its code was last read at. It is followed once a searched range leaves one candidate, and stays unresolved over a range that is not searched.

Two guards came from reading the first runs by hand, and review narrowed the first. The labels scored four wrong follows as correct, because the miner had paired the same definitions by chance:

  • Two dunder methods of 12 and 15 tokens in a deleted class were followed into an unrelated new class. Under 30 tokens a text is mostly its signature, and its own name is one any class may define. A definition that small now goes only with its scope: from module level to module level, or, once no member of its class is left in its file, into the class that is that one renamed alone or keeps at least two and at least half of its member names.
  • A related name was not enough for a definition that small. One shared word counts as related, and two stubs have the same tokens under any name: a removed class ReadError(Exception): pass was followed as moved to a new class RetryError(Exception): pass in another file, and its memory stayed in search as a lesson on the other class. A definition under 30 tokens is now followed only under a name of the same words: a leading underscore, the case or a v version may differ (_read_rows, read_rows_v2). The search of its own file and scope keeps the wider rule.
  • A removed sync client's get and delete were followed to a new async namesake, while the sync text lived on under a name the destination file already had. Rule 2 counted close candidates among new names only. It now refuses when a definition of that name that stayed in the changed files is close as well. A kept namesake still never inherits a link.

After the guards, measured again at the head commit (neither the narrower name rule nor the rule for a link already unresolved changed any of the 882 outcomes):

class n followed before followed now missing before missing now
rename in place, body at least 0.95 160 112 138 32 6
move, same name, body at least 0.95 110 105 105 0 0
move and rename, body at least 0.95 90 0 51 79 26
rename and edit 130 74 89 28 11
move and edit, same name 50 46 46 0 0
move, rename and edit 55 0 14 41 26
whole-file rename 50 50 50 0 0
old name kept as an alias (link stays) 50 50 50 0 0
deleted (read missing) 110 95 95 95 95

Read as removed although the code lives on: 230 of 722 (32%) before, 116 of 722 (16%) now. The 15 deletions read unresolved before are still unresolved. Every followed link carries the line range of the definition it went to (493 of 493).

Of the 110 links newly followed, one is scored as a wrong target and three as a part of a merge. Read by hand, all four are right: a function that became a nested definition of its own name inside a new wrapper (the miner counts no closures), and a method in a renamed test class. I read all 17 follows of a definition under 30 tokens and 17 of the larger ones (the lowest similarities and the generic names) and found no wrong one after the two guards. Those of them that went to another name differ from the old one by a leading underscore only. The other 76 have the exact shape or a similarity of 0.85 or more under a name specific to them and were not read one by one.

Scope and risk

  • server/code/domain/successor.py: elsewhere, a pure function beside successor, with the rules above. It reuses _similar, _renamed_alone, the name words and the member-share bounds of the same-file search.
  • server/memory/app/code_link_pass.py: RepoReads.turnover(base, head) reads, once per range and pass, what each changed file gained, lost and kept by the name inside its module, a renamed file as one file. It reads the files the ingest would index, by the checks the mirror search uses. It logs a warning for a range it did not read, and PassResult.wide_ranges counts those ranges for the pass that met them.
  • server/memory/app/code_link_recheck.py: _renamed_elsewhere runs after the same-file search, the search for the name in other files and the moved-with-an-edit search, only when all of them found nothing and none is unsure. A link already missing is never handed to a new definition, as before.
  • An unresolved link keeps the commit its code was last read at, so the range it is looked for over grows with every commit. Review found that once that range changed more than 32 files the link read missing with both candidates in place, and under retire_removed its memory left search. _renamed_elsewhere now answers unsure for a link already unresolved when the range is too wide or its diff cannot be read, the rule the search for namesakes has past the same bound.
  • What that costs: no later commit narrows such a range, so this search does not settle that link again. It stays unresolved until the search of its own file or for its own name finds it. The link row does not record which search left it unresolved, so this also holds for a link the same-file search left unresolved whose file later holds no candidate: over a range that is not searched it stays unresolved, where it read missing before this change. The warning is logged in every pass that rechecks such a link: every pass for 30 days after it became unresolved, and later ones that change its file or recheck every link.
  • What a reader sees change: a link that read missing can read moved, changed or unresolved. A memory the default policy left out of search is then served again; a changed one ranks below the next three results as any changed link does, and revise judges it.
  • A sentence of the concept page changes meaning. It said a namesake in another class or namespace never inherits a link. A namesake that was already there still never does. A definition of that name the range brought in can, under the rules above.
  • Cost: one diff per range (the recheck already has it for live links), and for each changed file under the entry's prefixes a names-only parse at both commits, a fingerprinted parse at the head, and one at the base when the file lost a name. The range is bounded at 32 such files (_MAX_ELSEWHERE, an existing constant); a wider one is not searched, a live link reads as it did before, and a warning in the server log names the range. The memory_code_links pass outcome counts the ranges that worker's own pass followed. A recheck that code.refresh runs keeps no outcome and sets the checked head, so a range it followed is in the log only. In the sample 45 of the 882 events are in a commit wider than that, and the warning was logged for 18 of them, in 8 commits (a pass logs it once for a range); an earlier search settled the link in the others. The read happens only when a link is lost and nothing else found it.
  • A file that does not parse adds no definition and no rival, as in the mirror search. It does not hold back the links of other files.
  • Left alone: a definition under 30 tokens that takes a name of other words as it moves (it reads missing, as before this change), a definition that takes a new own name as it moves and does not keep its exact shape (40 of the 52 still missing in the two move-and-rename rows changed their own name), merges and splits, kept aliases, the policies, the link rows and every reader.
  • Not measured: languages other than Python, ranges of several commits, several links of one memory, mass-reformat commits. The sample follows a fresh link over one commit, so it never rechecks an unresolved link: unit tests alone cover that rule.

Compatibility, rollout and rollback

  • Wire: none. The memory_code_links pass outcome gains the number wide_ranges, which workers.status serves as stored.
  • Schema, settings, generated files: none.
  • Rolling upgrade: one host rechecks a repository at a time, so a range is read by one build. A link the previous build reads missing during the rollout stays missing under this one until its own name returns (docs/architecture/rolling-upgrades.md, rule 66).
  • Operator steps: none. Links read missing before this change are not revisited.
  • Rollback: reverting leaves the links this build moved where they are; the previous build reads them as any followed link.
  • A moved and edited definition is followed past unrelated new definitions in its old scope #1669 edits the same condition in _recheck and the same paragraph of the concept page. Whichever lands second resolves a small conflict: the gate for both searches becomes "nothing found, and not unsure unless unmatched". I ran that composition on the sample, hand-resolved and unpushed: 14 links are followed that neither change follows alone (12 scored correct; the other two are the nested-definition case described above), and no follow of either change is lost. That run predates the narrower name rule; none of its follows is a definition under 30 tokens under a name of other words.

Tests

  • Not run locally: the unit and integration suites. CI runs them.
  • Run locally at the head commit: ruff format --check ., ruff check, the function-length gate, the secrets gate, every generator with --check, and the mypy gate (its only errors are in server/llm/vertex_auth.py, from a library missing in the local environment).
  • New unit tests, whose bodies I called directly with the real parser and the real RepoReads.turnover over a fake history: tests/unit/test_code_successor.py (a function and a class with its members renamed across files; a method that left its class or became a function reads changed; a small function under a name of the same words and of other words; a removed stub and a new stub that share a word; a small method with and without its class, with its class kept, and with an alias left behind; a close namesake that stayed; two candidates; a removed rival; twins), tests/unit/test_memory_code_links.py (through _recheck: file kept, deleted and renamed; a name the other file already had; a missing link not revived; the cap, its count and its warning; prefixes; a file that does not parse or the ingest refuses; the name searched before another name; the count reaching the pass outcome; an unresolved link rechecked over a second range that is too wide, that cannot be read, and that leaves one candidate), tests/unit/test_code_anchor.py (recheck with a successor in another file).
  • An autouse fixture stubs RepoReads.turnover for the older tests of that module, as one already stubs the mirror search: their fake histories answer no git diff.
  • New integration tests in tests/integration/test_memory_code_links.py, not run: a definition renamed into a new file is moved, served by memory.search and code.symbol under its new name, and missing once removed; a method of 30 tokens or more moved to another class reads changed.
  • Three existing integration tests assert missing for a small definition whose namesake appears in another class or namespace. I replayed their sources through the pure function and they still read missing.
  • Only a ClickHouse run can confirm: the link rows _write_moves writes for a rename across files (the former identity, policy_due), _current_moves, the lost-link reread (store.lost handing an unresolved link back with the commit _write_moves kept), the revise policy on a followed link, and the index's candidates in place of the fake index the measurement used.
  • The measurement harness is not in the repository. It makes a link at each event's parent commit with the linker's own row builder and runs _recheck over the commit with a real RepoReads on a bare clone; the index is replaced by a read of the clone at the head.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked by hand: the diagnosis against the code paths named above, the measurement before and after, every outcome that is not a plain follow, and the 34 follows listed above.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code


Note

Medium Risk
Changes core memory-to-code link resolution and search/lesson surfacing, with nuanced edge cases (small defs, wide diffs, unresolved state) but no schema or wire API break beyond a new pass metric.

Overview
Memory code links can now track a definition that moves to another file, class, or namespace under a new name, instead of stopping at missing. After the same-file successor search, mirror/name search, and “moved with edit” logic all come up empty, recheck calls new successor.elsewhere on definitions newly introduced in the changed files (via RepoReads.turnover).

Matching prefers an exact shape → moved, else a unique same-name body → changed, with extra guards for small definitions (scope + word-related names). Ambiguity yields unresolved; missing links are still not revived. Ranges touching more than 32 indexed paths are skipped (logged, counted as wide_ranges on the worker pass); already-unresolved links stay uncertain over those ranges.

Docs describe the behavior and rolling-upgrade rule 66; unit and integration tests cover the new paths.

Reviewed by Cursor Bugbot for commit 369475e. Bugbot is set up for automated code reviews on this repo. Configure here.

When a linked definition's name is gone from its file, the recheck searched
only that file and scope for a renamed successor, and other files only for
the same name. A definition renamed as it moved read `missing`, and under the
default policy its memory left search although the code lives on.

The recheck now also weighs the definitions the changed files did not define
at the range's base. The only one with the old exact shape is followed as a
rename alone; failing that, the only one of its own name with a close text is
followed as changed, unless a definition of that name that stayed in the
changed files is close as well. A member reads changed unless its class came
with it unchanged. A definition under 30 tokens is told by neither its text
nor a name any class may define, so it goes only under a related name and
with its scope. Two candidates, or one another removed definition may have
become, leave the link unresolved. A range that changed more than 32 files
under the entry's prefixes is not searched and is counted in the pass outcome
(`wide_ranges`). A link already missing is never handed to a new definition.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 28, 2026 2:14am UTC
loom-telemetry Ready Ready Preview Nov 28, 2026 2:14am UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/code_link_pass.py Resolved
zlareb1 and others added 4 commits November 28, 2026 04:21
The search of the other changed files admitted a definition under 30 tokens
under any related name, and one shared word past the common lead is a related
name. At that size the name-blanked shape of two stubs is the same, so a
removed `class ReadError(Exception): pass` was followed as `moved`, its
baseline replaced, to a new `class RetryError(Exception): pass` in any of up
to 32 changed files. Its memory stayed in search as a lesson on the other
class; without the search the link read `missing`.

A small definition is now followed there only under a name of the same words:
a leading underscore, the case or a `v` version may differ (`_read_rows`,
`read_rows_v2`). The search of its own file and scope is unchanged.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…rning

A recheck that `code.refresh` runs keeps only the errors of its result, and it
sets the checked head, so the link worker never follows that range: the
`wide_ranges` number of the worker's pass outcome does not count it. The one
trace both rechecks share is the log line in `RepoReads.turnover`, which is now
a warning. The concept page says what the pass outcome counts: the ranges the
worker's own pass followed.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A link the search across files leaves `unresolved` keeps the commit its code
was last read at, and every later pass looks for it from that commit. The
range only grows. Once it changed more than 32 files under the entry's
prefixes, `RepoReads.turnover` returned None, `_renamed_elsewhere` answered
that nothing became the definition, and the link read `missing` with both
candidates still in place. Under `retire_removed` its memory left search, and
a `missing` link is never handed to a new definition, so removing one
candidate later could not resolve it.

`_renamed_elsewhere` answers unsure for a link already `unresolved` when the
range is too wide or cannot be read, the rule the namesake search has past
`_MAX_ELSEWHERE`. A live link over such a range reads as it did.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Both sides changed the lost-link search in the recheck. A definition the
same-file search leaves unsure with no close text among the new definitions
there is still looked for under its own name in another module; the search
for one renamed as it moved runs only where the same-file search found no
new definition, as before this merge.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5592838. Configure here.

Comment thread server/code/domain/successor.py Resolved
zlareb1 and others added 3 commits November 28, 2026 07:12
…a renamed definition is searched for

`_file_turnover` read a file still present at the head whose names the ingest does not
index (over `code_ingest_max_file_bytes`, binary, or not parsing) as defining nothing
there, so every definition it had at the base joined `Turnover.gone`. `elsewhere` then
weighed them as rivals of the lost link's definition, and one of its shape left the
link `unresolved` where the renamed definition is in another file; `_vacated` read the
file's classes as emptied. Only a deleted file is evidence that its names left: a file
still there that is not indexed adds nothing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…d in it

The autouse stub of `RepoReads.turnover` answered None, which `_renamed_elsewhere`
reads as a range that was not searched, so an `unresolved` link stays `unresolved`.
`test_a_namesake_renamed_since_the_check_is_not_new[unresolved]` expects `missing`
once both candidates are gone and failed in CI. The stub answers an empty
`Turnover`: the range was searched and brought no definition in, which is what those
fake histories hold.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…hen most of that class is its own

`_may_be` took the destination class's members from the `new` side of its file, which
holds only the names the range brought in. The members the class already had are on
the `kept` side, so they were left out of the share: an existing class of five methods
that took the removed class's members in passed with a share of 1.0, and the link of a
method under 30 tokens went to it, while the same class new in the range was refused.
The members the file kept under that class now count in the share.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant